﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.ShprossesBuilder.Modelling.Components.Actions;
using ITAP.ShprossesBuilder.Modelling.Components;
using System.Drawing;

namespace ITAP.ShprossesBuilder.Manipulation
{
    public class CommandShprossConnectorsDiamondAlignment : SerializedUndoRedo, ICommand
    {
        private RectangleF activeModelBoundingBox;
        private double distance;
        private DiamondMeasure measure;
        public CommandShprossConnectorsDiamondAlignment(ModelControl modelControl, double distanceBetweenShprossConnectors, DiamondMeasure distanceMeasure)
        {
            this.modelControl = modelControl;
            this.distance = distanceBetweenShprossConnectors;
            this.measure = distanceMeasure;
        }
        #region ICommand Members

        public void StartExecute()
        {
            if (this.modelControl.ModelContainer.ActiveCell != null)
                this.activeModelBoundingBox = (this.modelControl.ModelContainer.ActiveCell as ModelCell).Model.BoundingBox;
            else
                this.activeModelBoundingBox = RectangleF.Empty;

            this.undoModelContainer = (ModelContainer)modelControl.ModelContainer.Clone();
            IComponentAction diamondAction = new ActionSelectedShprossConnectorsDiamondAlignment(this.modelControl, distance, measure, this.activeModelBoundingBox);
            diamondAction.Action(null);
        }

        public void Execute()
        {            
        }

        public void EndExecute()
        {
        }

        public bool IsNeedModelUpdate
        {
            get { return true; }
        }

        public string Name
        {
            get { return "Выравнивание соединителей по ромбу"; }
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            CommandShprossConnectorsDiamondAlignment clone = new CommandShprossConnectorsDiamondAlignment(modelControl, distance, measure);

            if (this.undoModelContainer != null)
                clone.undoModelContainer = (ModelContainer)this.undoModelContainer.Clone();
            if (this.redoModelContainer != null)
                clone.redoModelContainer = (ModelContainer)this.redoModelContainer.Clone();

            return clone;
        }

        #endregion

        public override string ToString()
        {
            return this.Name;
        }

        #region ICommand Members


        private bool enabled = true;
        public bool Enabled
        {
            get
            {
                return enabled;
            }
            set
            {
                enabled = value;
            }
        }

        #endregion

        #region ICommand Members


        public bool IsNeedVisitorsUpdate
        {
            get { return true; }
        }

        #endregion
    }
}
